package me.yricky.mayu.desktop

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.CatchingPokemon
import androidx.compose.runtime.*
import me.yricky.mayu.ui.fasta_box.FastaBoxesModel
import me.yricky.mayu.ui.fasta_box.Page
import me.yricky.mayu.ui.file_list.FileBrowseModel
import me.yricky.mayu.ui.file_list.Page
import me.yricky.mayu.ui.tasks.Page
import me.yricky.mayu.ui.tasks.TasksListModel

/**
 * @author Yricky
 * @date 2022/4/18
 */
object AppState {
    val fileBrowseModel by lazy{
        FileBrowseModel(null){
            if(it.isFile){
                when(it.extension.uppercase()){
                    "FASTA", "FNA","FFN","FAA","FRN","TXT" -> Icons.Rounded.CatchingPokemon
                    else-> null
                }

            }else null
        }.apply {
            openMethod = {
                if(it.isFile){
                    when(it.extension.uppercase()){
                        "FASTA", "FNA","FFN","FAA","FRN","TXT" -> {
                            navigate(ToSeqList{ model -> model.add(it) })
                        }
                    }
                }
            }
        }
    }

    val fastaBoxesModel by lazy { FastaBoxesModel() }
    val tasksListModel by lazy { TasksListModel() }

    val workList = mutableStateListOf<Pair<Any,@Composable ()->Unit>>()

    val fileListContent:@Composable ()->Unit = { fileBrowseModel.Page() }
    val seqListContent:@Composable ()->Unit = { fastaBoxesModel.Page{ it.openDetail() } }
    val taskListContent:@Composable ()->Unit = { tasksListModel.Page() }
    var mainWindowContent:@Composable ()->Unit by mutableStateOf(fileListContent)
    private set

    sealed class Navigation
    fun navigate(navigation: Navigation){
        when(navigation){
            is ToFileList ->{
                navigation.action(fileBrowseModel)
                mainWindowContent = fileListContent
            }
            is ToSeqList ->{
                navigation.action(fastaBoxesModel)
                mainWindowContent = seqListContent
            }
            is ToTaskList ->{
                navigation.action(tasksListModel)
                mainWindowContent = taskListContent
            }
            else -> { }
        }
    }
}
